
*===================================================================*
*																	*
*				Legal Identity at the Margins: 						*
*	The Impact of Violent Conflict on Birth Registration in India	*
*      	   		Atharv Dhiman & Imke Harbers      					*
*																	*
*===================================================================*

*===================================================================*
* 					REPLICATION FILE Analysis and Tables			*
*===================================================================*

* Stata Version: 16.0
* IF NECESSARY: INSTALL PACKAGES 
* ssc install estout
* ssc install coefplot
* ssc install asdoc
* net install asdoc, from(http://fintechprofessor.com) replace // asdoc seems to be deprecated, this does seem to help to install it

***** 
* DHS data needs to be downloaded directly from the DHS website: https://dhsprogram.com/data/dataset/India_Standard-DHS_2015.cfm
* The relevant file for this analysis is the Stata file of the Household Member Recode "\IAPR74DT\IAPR74FL.DTA". 
* Save this file in the same directory as the replication files. 

use "IAPR74FL.DTA"

*** Data Preparation

* generate dummy to reflect whether a child has a birth certificate
gen BR_dummy = 1 if hv140 == 1
replace BR_dummy = 0 if hv140 == 0 | hv140 == 2 | hv140 == 8
tab BR_dummy hv140

* generate dummy for girls
gen female = 1 if hv104 == 2
replace female = 0 if hv104 == 1
tab female hv104

*generate dummy for households in urban areas
gen urban = 1 if hv025 == 1
replace urban = 0 if hv025 == 2
tab hv025 urban

*consolidate and simplify religious categories
gen religion = sh34 
replace religion = 96 if religion > 4 & religion < 9
label values religion SH34

* add conflict data and merge by PSU
merge m:1 hv021 using "UCDP_Conflict_Data.dta"
* 2 observations lost in merge; these appear to be clusters where nobody was sampled 
drop _merge 

* add terrain data and merge by district 
merge m:1 shdistri using "District-level Terrain Data.dta"

* log transformation Conflict Exposure
gen log_conflict = Conflict +1
replace log_conflict = log(log_conflict)

*** Analysis***

* Table 1
* Model 1: Logit model 
logit BR_dummy Conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 
estimates store m1, title(Model 1)

* Model 2: Logit model with state fixed effects
logit BR_dummy Conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024
estimates store m2, title(Model 2)

* Model 3: Multi-level logit model with state fixed-effects and districts as second level
melogit BR_dummy Conflict  i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024 || shdistri:
estimates store m3, title(Model 3)
estat icc

* Export Table 1
esttab * using table1.rtf, replace onecell cells(b(star fmt(%9.3f)) se(par)) stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared)) legend label collabels() varlabels(_cons Constant) nolz

* Figure 3
coefplot (m1, label (Model 1)) (m2, label (Model 2)) (m3, label (Model 3)) , drop (_cons) keep (Conflict*) xline(0) xlabel (-.08(.02).08) rename(Conflict = "Conflict Exposure") scheme(s2mono)

*** Calculations of predicted probabilities reported in the text
* predicted probabilities (Model 1)
logit BR_dummy Conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 
*Hindu girl, mother no education, rural area, member of scheduled caste, lowest wealth quintile, Conflict at 0 and 18
margins, at(Conflict = (0 18) female = 1 religion = 1 hc68=0  urban = 0 sh36= 1 hv270 = 1) atmeans post 

logit BR_dummy Conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 
*Hindu girl, mother no education, rural area, member of scheduled caste, lowest wealth quintile, Conflict at 0 and 2.8 (footnote)
margins, at(Conflict = (0 2.8) female = 1 religion = 1 hc68=0  urban = 0 sh36= 1 hv270 = 1) atmeans post 

** predicted probabilities (Model 2)
logit BR_dummy Conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024
*Christian boy in Manipur, mother has some education, rural area, lowest wealth quintile, member of scheduled tribe
margins, at(Conflict = (.375113 3.10552) religion = 3 female = 0 hv024=21 hc68=1  urban = 0 hv270 = 1  sh36= 2 ) atmeans post 

** predicted probabilities (Model 3)
melogit BR_dummy Conflict  i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024 || shdistri:
* Muslim boy Jammu and Kashmir, rural area, lowest wealth quintile, mother has no education, member of scheduled tribe
margins, at(Conflict = (.0000307 24.9061) religion = 2 female = 0 hv024=14 urban = 0 hv270 = 1 hc68=0 sh36= 2 ) atmeans post 


***Descriptive Statistics (Appendix 1)
asdoc summarize BR_dummy Conflict log_conflict i.hc68 female hv105 urban i.hv270 i.sh36 i.religion STD hv040 av_for2010 if BR_dummy ~=., label replace dec(2) replace

***Robustness Checks - Linear Models (Appendix 2)
* Model A1: OLS model with standard errors clustered at the district-level
reg BR_dummy Conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010, cluster(shdistri)
estimates store mA1, title(Model A1)

* Model A2: OLS model with state fixed-effects and standard errors clustered at the district level
reg BR_dummy Conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024, cluster(shdistri)
estimates store mA2, title(Model A2)

* Model A3: Multi-level mixed-effects linear model with state fixed effects and districts as second level
xtmixed BR_dummy Conflict  i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024 || shdistri:
estimates store mA3, title(Model A3)
estat icc

esttab mA1 mA2 mA3 using appendix2.rtf, replace onecell cells(b(star fmt(%9.3f)) se(par)) stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared)) legend label collabels() varlabels(_cons Constant) nolz

***Robustness Checks - Log Transformation (Appendix 3)


* Model A4: Logit model with log transformation
logit BR_dummy log_conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 
estimates store mA4, title(Model A4)

* Model A5: Logit model with log transformation and state fixed effects
logit BR_dummy log_conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024
estimates store mA5, title(Model A5)

* Model A6: Multi-level logit model with log transformation and state fixed-effects and districts as second level
melogit BR_dummy log_conflict  i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024 || shdistri:
estimates store mA6, title(Model A6)
estat icc

* Model A7 OLS model with log transformation and standard errors clustered at the district-level
reg BR_dummy log_conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010, cluster(shdistri)
estimates store mA7, title(Model A7)

* Model A8: OLS model with log transformation and state fixed-effects and standard errors clustered at the district level
reg BR_dummy log_conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024, cluster(shdistri)
estimates store mA8, title(Model A8)

* Model A9: Multi-level mixed-effects linear model with log transformation and state fixed effects and districts as second level
xtmixed BR_dummy log_conflict i.hc68 female hv105 urban i.hv270 ib4.sh36 i.religion STD hv040 av_for2010 i.hv024 || shdistri:
estimates store mA9, title(Model A9)
estat icc

esttab mA4 mA5 mA6 mA7 mA8 mA9 using appendix3.rtf, replace onecell cells(b(star fmt(%9.3f)) se(par)) stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared)) legend label collabels() varlabels(_cons Constant) nolz